package org.bright.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class UserAdvice {
    private static final Logger logger = Logger.getLogger(UserAdvice.class);
    @Pointcut("execution(* org.bright.service.Impl.*.*(..))")
    private void UserM(){}

    @Before(value = "UserM()")
    private void method(){
        logger.debug("方法开始调用之前"+System.currentTimeMillis());
    }

    @After(value = "UserM()")
    private void methodAfter() {
        logger.debug("方法调用之后"+System.currentTimeMillis());
    }
    @Around(value = "UserM()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        logger.debug("开始环绕通知");
        //        获取参数

        logger.debug("参数"+ Arrays.toString(pjp.getArgs()));
        logger.debug("环绕通知，调用哪个类\t\t"+pjp.getTarget());
        logger.debug("环绕通知，调用哪个类里的哪个方法\t\t"+pjp.getSignature().getName());

        Object result = pjp.proceed();



        logger.debug("around after 接收");
        return result;
    }
}
